---@class Battle.AiBehavior
---@field New fun():Battle.AiBehavior
local AiBehavior = Battle.CreateClass("AiBehavior")
Battle.AiBehavior = AiBehavior
local t = AiBehavior
function t:ctor(behaviorType)
    ---@type Battle.AiTree
    self.treeRoot = nil
    ---@type Battle.AiBehavior
    self.parent = nil
    self.behaviorType = behaviorType
end
function t:SetParamKey(index,key)
    if not self.__paramKeyList then
        self.__paramKeyList = {}
    end
    self.__paramKeyList[key] = index
    return self
end
function t:GetParam(key)
    local index
    if self.__paramKeyList then
        index = self.__paramKeyList[key]
    end
    if not index then
        index = key
    end
    local d = self.__param[index]
    if type(d) == "function" then
        return d(self:GetTree().actor)
    else
        return d
    end
end
---@private
function t:SetParam(...)
    self.__param = {...}
end

function t:tick(dt)
    if self.status == Battle.AiTreeStatus.SUCCESS or self.status == Battle.AiTreeStatus.FAILURE then
        return self.status
    end
    return self:doTick(dt)
end
function t:doTick(dt)
    if self.status ~= Battle.AiTreeStatus.RUNNING then
        self:onInitialize();
    end
    self:GetTree():AddExecute(self)
    self.status = self:update(dt)
    return self.status
end
function t:reset()
    self.status = Battle.AiTreeStatus.INVALID
end
---@return Battle.AiTree
function t:GetTree()
    if self.treeRoot then
        return self.treeRoot
    end
    if self.parent then
        local root = self.parent:GetTree()
        self.treeRoot = root
    end
    return self.treeRoot
end
---@return Battle.AiBlackboard
function t:GetBlackboard()
    local tree = self:GetTree()
    return tree.blackboard
end
---@return Battle.Entity
function t:GetActor()
    local tree = self:GetTree()
    return tree.actor
end
function t:Awake()

end
function t:onInitialize()

end
function t:onTerminate()

end
function t:update(dt)
    return Battle.AiTreeStatus.SUCCESS
end
function t:ToString()
    return self.__cname.." actor:"..self:GetActor().id.." status:"..self.status
end